/*
	This file is part of the OdinMS Maple Story Server
    Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc> 
                       Matthias Butz <matze@odinms.de>
                       Jan Christian Meyer <vimes@odinms.de>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License version 3
    as published by the Free Software Foundation. You may not use, modify
    or distribute this program under any other version of the
    GNU Affero General Public License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package org.snow.odinms;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public enum RecvPacketOpcode implements WritableIntValueHolder {

        //中國伺服器新增包
        ENTER,
        SET_GENDER,
        LICENSE_REQUEST,
        CLIENT_FEEDBACK,


        // General
        RSA_KEY,
        STRANGE_DATA,
        MAPLETV,
        LOGIN_REDIRECTOR,
        CRASH_INFO,
        PONG,//145
        // Login
        GUEST_LOGIN,
        SERVERSTATUS_REQUEST,
        TOS,
        VIEW_SERVERLIST,
        SERVERLIST_REQUEST,
        REDISPLAY_SERVERLIST,
        CHAR_SELECT_NO_PIC,
        PLAYER_LOGGEDIN,
        CHECK_CHAR_NAME,
        DELETE_CHAR,
        AUTH_REQUEST,
        CHAR_SELECT,
        VIEW_REGISTER_PIC,
        VIEW_SELECT_PIC,
        CLIENT_START,
        CLIENT_FAILED,
        PART_TIME_JOB,
        CHARACTER_CARD,
        ENABLE_LV50_CHAR,
        CREATE_LV50_CHAR,
        ENABLE_SPECIAL_CREATION,
        CLIENT_HELLO,
        LOGIN_PASSWORD,
        CREATE_SPECIAL_CHAR,
        CHARLIST_REQUEST,
        CREATE_CHAR,
        CREATE_ULTIMATE,
        AUTH_SECOND_PASSWORD,
        WRONG_PASSWORD,//v145
        CLIENT_ERROR,
        /*
         * Channel Opcodes.
         * Used for in-game packets.
         */
        CHANGE_MAP,//51
        CHANGE_CHANNEL,//52
        ENTER_CASH_SHOP,//54
        ENTER_FARM,
        ENTER_AZWAN,
        ENTER_AZWAN_EVENT,
        LEAVE_AZWAN,
        ENTER_PVP,
        ENTER_PVP_PARTY,
        LEAVE_PVP,
        MOVE_PLAYER,//5E
        CANCEL_CHAIR,//60
        USE_CHAIR,//61
        CLOSE_RANGE_ATTACK,//62
        RANGED_ATTACK,//63
        MAGIC_ATTACK,//64
        PASSIVE_ENERGY,//65
        TAKE_DAMAGE,//68
        PVP_ATTACK,
        GENERAL_CHAT,//6A
        CLOSE_CHALKBOARD,//6B
        FACE_EXPRESSION,//6C
        FACE_ANDROID,//6D
        USE_ITEMEFFECT,//6E
        WHEEL_OF_FORTUNE,//6F
        USE_TITLE,//71
        ANGELIC_CHANGE,//72
        CHANGE_CODEX_SET,//7A
        CODEX_UNK,//7B
        MONSTER_BOOK_DROPS,//7C
        NPC_TALK,//7F
        NPC_TALK_MORE,//81
        NPC_SHOP,//82
        STORAGE,//84
        USE_HIRED_MERCHANT,//84
        MERCH_ITEM_STORE,//85
        PACKAGE_OPERATION,//87
        MECH_CANCEL,//87
        OWL,//8A
        OWL_WARP,//8A
        ITEM_SORT,//92
        ITEM_GATHER,//93
        ITEM_MOVE,//94
        MOVE_BAG,//95
        SWITCH_BAG,//96
        USE_ITEM,//98
        CANCEL_ITEM_EFFECT,//99
        USE_SUMMON_BAG,//9B
        PET_FOOD,//9C
        USE_MOUNT_FOOD,//9D
        USE_SCRIPTED_NPC_ITEM,//9E
        USE_RECIPE,//9D
        USE_NEBULITE,//9E
        USE_ALIEN_SOCKET,//9F
        USE_ALIEN_SOCKET_RESPONSE,//A0
        USE_NEBULITE_FUSION,//A1
        USE_CASH_ITEM,//A2
        USE_CATCH_ITEM,//A4
        USE_SKILL_BOOK,//A9
        USE_EXP_POTION,//A8
        TOT_GUIDE,//B6
        USE_OWL_MINERVA,//BA
        USE_TELE_ROCK,//BB
        USE_RETURN_SCROLL,//BC
        USE_UPGRADE_SCROLL,//BD
        USE_FLAG_SCROLL,//BE
        USE_EQUIP_SCROLL,//BF
        USE_POTENTIAL_SCROLL,//C3
        USE_ABYSS_SCROLL,//C4
        USE_CARVED_SEAL,//C5
        USE_BAG,
        USE_CRAFTED_CUBE,
        USE_MAGNIFY_GLASS,//CA
        DISTRIBUTE_AP,//CD
        AUTO_ASSIGN_AP,//CE
        HEAL_OVER_TIME,//CF
        DISTRIBUTE_SP,//D2
        SPECIAL_MOVE,//D3
        CANCEL_BUFF,//D4
        SKILL_EFFECT,//D5
        MESO_DROP,//D6
        GIVE_FAME,//D7
        CHAR_INFO_REQUEST,//D9
        SPAWN_PET,//DA
        GET_BOOK_INFO,//DC
        USE_FAMILIAR,//DD
        SPAWN_FAMILIAR,//DE
        RENAME_FAMILIAR,//DF
        PET_BUFF,//E0
        CANCEL_DEBUFF,//E1
        CHANGE_MAP_SPECIAL,//e2
        USE_INNER_PORTAL,//E3
        TROCK_ADD_MAP,//e4
        LIE_DETECTOR,//E5
        LIE_DETECTOR_SKILL,//E6
        LIE_DETECTOR_RESPONSE,//E7
        REPORT,//E9
        QUEST_ACTION,//EA
        REISSUE_MEDAL,//EB
    //    BUFF_RESPONSE,//EC
        SKILL_MACRO,//F0
        REWARD_ITEM,//F2
        ITEM_MAKER,
        REPAIR_ALL,//C7
        REPAIR,//C8
        SOLOMON,//C9
        GACH_EXP,//CA
        FOLLOW_REQUEST,//FD
        PQ_REWARD,//FE
        FOLLOW_REPLY,//101
        AUTO_FOLLOW_REPLY,
        USE_TREASURE_CHEST,
        PROFESSION_INFO,
        USE_POT,//D6
        CLEAR_POT,
        FEED_POT,
        CURE_POT,
        REWARD_POT,
        AZWAN_REVIVE,
        USE_COSMETIC,
        INNER_CIRCULATOR,
        PVP_RESPAWN,
        GAIN_FORCE,
        ADMIN_CHAT,
        PARTYCHAT,
        COMMAND,
        SPOUSE_CHAT,
        MESSENGER,
        PLAYER_INTERACTION,
        PARTY_OPERATION,
        DENY_PARTY_REQUEST,
        ALLOW_PARTY_INVITE,//12F
        EXPEDITION_OPERATION,//130
        EXPEDITION_LISTING,
        GUILD_OPERATION,
        DENY_GUILD_REQUEST,
        ADMIN_COMMAND,//12C
        ADMIN_LOG,//12D
        BUDDYLIST_MODIFY, //12E
        NOTE_ACTION,//12F
        USE_DOOR,//131
        USE_MECH_DOOR,//132
        CHANGE_KEYMAP, //13D
        RPS_GAME,
        RING_ACTION,
        WEDDING_ACTION,
        ALLIANCE_OPERATION,//13B
        DENY_ALLIANCE_REQUEST,//13C
        REQUEST_FAMILY,//13D
        OPEN_FAMILY,//13E
        FAMILY_OPERATION,//13F
        DELETE_JUNIOR,//140
        DELETE_SENIOR,//141
        ACCEPT_FAMILY,//142
        USE_FAMILY,//143
        FAMILY_PRECEPT,//144
        FAMILY_SUMMON,//145
        BBS_OPERATION,//150
        SOLOMON_EXP,//151
        NEW_YEAR_CARD,
        XMAS_SURPRISE,
        TWIN_DRAGON_EGG,
        ARAN_COMBO,//0x152
        TRANSFORM_PLAYER,
        CYGNUS_SUMMON,
        CRAFT_DONE,//157
        CRAFT_EFFECT,//158
        CRAFT_MAKE,//159
        CHANGE_ROOM_CHANNEL,//15D
        EVENT_CARD,//15E
        CHOOSE_SKILL,//15F
        SKILL_SWIPE,//160
        VIEW_SKILLS,//161
        CANCEL_OUT_SWIPE,//162
        YOUR_INFORMATION,//163
        FIND_FRIEND,//164
        PINKBEAN_CHOCO_OPEN,//165
        PINKBEAN_CHOCO_SUMMON,//166
        BUY_SILENT_CRUSADE,
        CASSANDRAS_COLLECTION,//new v145
        BUDDY_ADD,
        MOVE_PET,//1A8
        PET_CHAT,//1A9
        PET_COMMAND,//1AA
        PET_LOOT,//1AB
        PET_AUTO_POT,//1AC
        PET_IGNORE,//1AD
        MOVE_HAKU,//1B1
        CHANGE_HAKU,//1B2
        //HAKU_1D8,//test
        //HAKU_1D9,//test
        MOVE_SUMMON,//1b8
        SUMMON_ATTACK,//1B9
        DAMAGE_SUMMON,//1BA
        SUB_SUMMON,//1BB
        REMOVE_SUMMON,//1BC
        PVP_SUMMON,//1BE
        MOVE_DRAGON,//1C0
        USE_ITEM_QUEST,//1C4
        MOVE_ANDROID,//1C5
        UPDATE_QUEST,//1C7//+16
        QUEST_ITEM,//1D6
        MOVE_FAMILIAR,//1DC
        TOUCH_FAMILIAR,//1DD
        ATTACK_FAMILIAR,//1DE
        REVEAL_FAMILIAR,//1DF
        QUICK_SLOT,
        PAM_SONG,
        AUTO_AGGRO,//210
        FRIENDLY_DAMAGE,//211
        MONSTER_BOMB,//212
        HYPNOTIZE_DMG,//213
        MOVE_LIFE,//20C
        MOB_BOMB,//217
        MOB_NODE,//218
        DISPLAY_NODE,//219
        MONSTER_CARNIVAL,//21A
        NPC_ACTION,//226
        ITEM_PICKUP,//22A
        DAMAGE_REACTOR,//22E
        TOUCH_REACTOR,//22F
        CLICK_REACTOR,//230
        MAKE_EXTRACTOR,//231
        UPDATE_ENV,
        SNOWBALL,
        LEFT_KNOCK_BACK,
        CANDY_RANKING,
        COCONUT,
        LUCKY_LUCKY_MONSTORY,//new v147
        SHIP_OBJECT,
        PARTY_SEARCH_START,//24B
        PARTY_SEARCH_STOP,//24C
        START_HARVEST,//24E
        STOP_HARVEST,//24F
        QUICK_MOVE,//19E
        CS_UPDATE,//28E
        BUY_CS_ITEM,//28F
        COUPON_CODE,//28F
        CASH_CATEGORY,//295
        PLACE_FARM_OBJECT,
        FARM_SHOP_BUY,
        FARM_COMPLETE_QUEST,
        FARM_NAME,
        HARVEST_FARM_BUILDING,
        USE_FARM_ITEM,
        RENAME_MONSTER,
        NURTURE_MONSTER,
        EXIT_FARM,
        FARM_QUEST_CHECK,
        FARM_FIRST_ENTRY,
        GOLDEN_HAMMER,
        VICIOUS_HAMMER,
        PYRAMID_BUY_ITEM,
        CLASS_COMPETITION,
        MAGIC_WHEEL,
        REWARD,
        BLACK_FRIDAY,
        RECEIVE_GIFT_EFFECT,//new v145
        UPDATE_RED_LEAF,
        //Not Placed:
        SPECIAL_STAT,//107
        UPDATE_HYPER,//
        RESET_HYPER,//
        DRESSUP_TIME,
        DF_COMBO,
        BUTTON_PRESSED,//1D3
        OS_INFORMATION,//1D6
        LUCKY_LOGOUT,
        MESSENGER_RANKING,
        UNKNOWN;

        private int code = -2;

	public void setValue(int code) {
		this.code = code;
	}

	@Override
	public int getValue() {
		return code;
	}

	public static Properties getDefaultProperties() throws FileNotFoundException, IOException {
		Properties props = new Properties();
		FileInputStream fis = new FileInputStream(System.getProperty("net.sf.odinms.recvops"));
		props.load(fis);
		fis.close();
		return props;
	}

	public static RecvPacketOpcode getByType(int type) {
		for (RecvPacketOpcode l : RecvPacketOpcode.values()) {
			if (l.getValue() == type) {
				return l;
			}
		}
		return UNKNOWN;
	}

	public static RecvPacketOpcode getByName(String name) {
		for (RecvPacketOpcode l : RecvPacketOpcode.values()) {
			if (l.name().equalsIgnoreCase(name)) {
				return l;
			}
		}
		return UNKNOWN;
	}


	static {
		try {
			ExternalCodeTableGetter.populateValues(getDefaultProperties(), values());
		} catch (IOException e) {
			throw new RuntimeException("Failed to load recvops", e);
		}
	}
}
